package com.lzdongrui.backend.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.lzdongrui.backend.domain.dto.InstructorDTO;
import com.lzdongrui.backend.domain.vo.InstructorVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lzdongrui.common.annotation.Log;
import com.lzdongrui.common.core.controller.BaseController;
import com.lzdongrui.common.core.domain.AjaxResult;
import com.lzdongrui.common.enums.BusinessType;
import com.lzdongrui.backend.domain.Instructor;
import com.lzdongrui.backend.service.IInstructorService;
import com.lzdongrui.common.utils.poi.ExcelUtil;
import com.lzdongrui.common.core.page.TableDataInfo;

/**
 * 辅导员Controller
 * 
 * @author wyh
 * @date 2023-05-19
 */
@RestController
@RequestMapping("/backend/instructor")
public class InstructorController extends BaseController
{
    @Autowired
    private IInstructorService instructorService;

    /**
     * 查询辅导员列表
     */
    @PreAuthorize("@ss.hasPermi('backend:instructor:list')")
    @GetMapping("/list")
    public TableDataInfo list(InstructorDTO instructorDTO)
    {
        startPage();
        List<InstructorVO> list = instructorService.selectInstructorList(instructorDTO);
        return getDataTable(list);
    }

    /**
     * 导出辅导员列表
     */
    @PreAuthorize("@ss.hasPermi('backend:instructor:export')")
    @Log(title = "辅导员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InstructorDTO instructorDTO)
    {
        List<InstructorVO> list = instructorService.selectInstructorList(instructorDTO);
        ExcelUtil<InstructorVO> util = new ExcelUtil<InstructorVO>(InstructorVO.class);
        util.exportExcel(response, list, "辅导员班级数据");
    }

    /**
     * 获取辅导员详细信息
     */
    @PreAuthorize("@ss.hasPermi('backend:instructor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(instructorService.selectInstructorById(id));
    }

    /**
     * 新增辅导员
     */
    @PreAuthorize("@ss.hasPermi('backend:instructor:add')")
    @Log(title = "辅导员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Instructor instructor)
    {
        instructor.setOperator(getUserId());
        return toAjax(instructorService.insertInstructor(instructor));
    }

    /**
     * 修改辅导员
     */
    @PreAuthorize("@ss.hasPermi('backend:instructor:edit')")
    @Log(title = "辅导员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Instructor instructor)
    {
        instructor.setOperator(getUserId());
        return toAjax(instructorService.updateInstructor(instructor));
    }

    /**
     * 删除辅导员
     */
    @PreAuthorize("@ss.hasPermi('backend:instructor:remove')")
    @Log(title = "辅导员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(instructorService.deleteInstructorByIds(ids));
    }

    /**
     * 批量修改辅导员
     */
    @PreAuthorize("@ss.hasPermi('backend:instructor:edit-more')")
    @Log(title = "批量修改辅导员", businessType = BusinessType.UPDATE)
    @PutMapping("/moreEdit/{ids}/{instructor}")
    public AjaxResult moreEdit(@PathVariable Long[] ids,@PathVariable Long instructor)
    {
        Long Operator = getUserId();
        return toAjax(instructorService.moreEdit(ids,instructor,Operator));
    }

    /**
     * 新增辅导员
     */
    @PreAuthorize("@ss.hasPermi('backend:instructor:add-more')")
    @Log(title = "批量设置辅导员", businessType = BusinessType.INSERT)
    @PostMapping("/moreAdd/{ids}/{instructor}")
    public AjaxResult moreAdd(@PathVariable Long[] ids,@PathVariable Long instructor)
    {
        Long Operator = getUserId();
        return toAjax(instructorService.moreAdd(ids,instructor,Operator));
    }
}
